package num1047;

import java.util.Arrays;
import java.util.LinkedList;

/**
 * @author : DuJiabao
 * @Project : sword-finger-offer
 * @Time : 2021/5/8 20:05
 * @Desc :
 */
class Solution {
  public String removeDuplicates(String S) {
    StringBuilder res = new StringBuilder();
    for (char c : S.toCharArray()) {
      int length = res.length();
      if (length == 0 || res.charAt(length - 1) != c) {
        res.append(c);
      } else {
        res.deleteCharAt(length - 1);
      }
    }
    return res.toString();
  }

  public static void main(String[] args) {
    String res = new Solution().removeDuplicates("abbaca");
    System.out.println(res);
  }
}
